package entities;

import java.util.Date;

/**
 * General person class, should be extended for practical use A person has a
 * name, a unique id number, and a date of birth
 * 
 * @author gke703
 */
public class Person {

	/** name of the person */
	private String name;

	/** unique identification for the person */
	private int id;

	/** Person's date of birth */
	private Date birthdate;

	/** Person's current address */
	private String address;

	/** Person's current phone number */
	private String phoneNumber;

	/** Person's current e-mail address */
	private String eMail;

	/**
	 * person constructor, set unique id
	 * 
	 * @param id
	 *            int person's unique id
	 */
	public Person(int myid) {
		id = myid;
		name = "";
		birthdate = null;
		address = null;
		phoneNumber = null;
		eMail = null;
	}

	/**
	 * accessor method for person's name
	 * 
	 * @return String person's name
	 **/
	public String getName() {

		return name;
	}

	/**
	 * mutator method for person's name
	 * 
	 * @param myName
	 *            the name to be set
	 */
	public void setName(String myName) {
		name = myName;
	}

	/**
	 * accessor for person's id
	 * 
	 * @return int unique person id
	 */
	public int getID() {
		return id;
	}

	/***
	 * accessor for the person's date of birth
	 * 
	 * @return Date person's date of birth
	 */
	public Date getBirthdate() {

		return birthdate;
	}

	/**
	 * 
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public String getBirthdateAsString() {
		Date mydate = birthdate;
		String myDateString = "";

		int month = mydate.getMonth() + 1;
		if (month < 10) {
			myDateString += "0" + month + "/";
		} else {
			myDateString += month + "/";
		}

		if (mydate.getDate() < 10) {
			myDateString += "0" + mydate.getDate() + "/";
		} else {
			myDateString += mydate.getDate() + "/";
		}

		myDateString += mydate.getYear() + 1900;

		return myDateString;
	}

	/**
	 * mutator for person's date of birth
	 * 
	 * @param Date
	 *            person's birth of date
	 */
	public void setBirthdate(Date myBirthdate) {

		birthdate = myBirthdate;
	}

	/**
	 * mutator for person's date of birth
	 * 
	 * @param myBirthdate
	 *            String date in the format "MM/dd/yyyy"
	 */
	@SuppressWarnings("deprecation")
	public void setBirthdate(String myBirthdate) {
		if (myBirthdate.matches("[0-1][0-9]/[0-3][0-9]/[0-2][90][0-9][0-9]")) {

			Date mydate = new Date();
			mydate.setMonth(Integer.parseInt(myBirthdate.substring(0, 2)) - 1);
			mydate.setDate(Integer.parseInt(myBirthdate.substring(3, 5)));
			mydate.setYear(Integer.parseInt(myBirthdate.substring(6, 10)) - 1900);
			birthdate = mydate;
		}
	}

	/**
	 * accessor for person's current address
	 * 
	 * @return String person's current address
	 */
	public String getAddress() {

		return address;
	}

	/**
	 * sets person's current address
	 * 
	 * @param myAddress
	 *            String, person's current address
	 */
	public void setAddress(String myAddress) {

		address = myAddress;
	}

	/**
	 * accessor for person's current phone number
	 * 
	 * @return String person's current phone number
	 */
	public String getPhoneNumber() {

		return phoneNumber;
	}

	/**
	 * sets person's current Phone Number, preferred format ie 1-(306)-211-2121
	 * 
	 * @param myAddress
	 *            String, person's current phone number
	 */
	public void setPhoneNumber(String myPhone) {

		phoneNumber = myPhone;
	}

	/**
	 * Accessor for Person's e-mail
	 * 
	 * @return String Person's current e-mail address
	 */
	public String getEmail() {

		return eMail;
	}

	/**
	 * Mutator for person's e-mail
	 * 
	 * @param myEmail
	 *            String, Person's current e-mail address
	 */
	public void setEmail(String myEmail) {

		eMail = myEmail;
	}

	/**
	 * regression tests
	 * 
	 * @param args
	 */
	@SuppressWarnings("deprecation")
	public static void main(String[] args) {

		Person myPerson = new Person(0);

		if (myPerson.getID() != 0) {
			System.out.println("problem setting/returning unique id");
		}

		if (myPerson.getName() != "") {
			System.out.println("problem initializing name");
		}

		myPerson.setName("Graham");

		if (myPerson.getName() != "Graham") {
			System.out.println("problem setting/retriecing person name");
		}

		myPerson.setBirthdate("06/07/2010");
		Date testdate = myPerson.getBirthdate();
		if (testdate.getDate() != 7 || testdate.getMonth() + 1 != 6
				|| testdate.getYear() + 1900 != 2010) {
			System.out.println("problem storing/retrieving birthdate");
		}

		if (!myPerson.getBirthdateAsString().equals("06/07/2010")) {
			System.out.println("Problem retrieving birthdate as string");
		}

		if (myPerson.getAddress() != null) {
			System.out.println("problem initializing address");
		}

		myPerson.setAddress("210 Main St.");
		if (myPerson.getAddress() != "210 Main St.") {
			System.out.println("problem setting address");
		}

		if (myPerson.getEmail() != null) {
			System.out.println("problem initializing Email");
		}

		myPerson.setEmail("ghj786@usask.mail.ca");
		if (myPerson.getEmail() != "ghj786@usask.mail.ca") {
			System.out.println("problem storing eMail");
		}

		if (myPerson.getPhoneNumber() != null) {
			System.out.println("problem initializing phone number");
		}

		myPerson.setPhoneNumber("1-(306)-211-2121");
		if (myPerson.getPhoneNumber() != "1-(306)-211-2121") {
			System.out.println("problem storing phone Number");
		}

	}

}
